package fragments.shopfragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.travel.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import shopbean.contans.GoodsBean;

/**
 * Created by Administrator on 2016/10/24.
 */
public class GoodsAdapter extends BaseAdapter {
    public GoodsAdapter(Context context, List<GoodsBean.DataBean.LineBean> list) {
        this.context = context;
        this.list = list;
    }

    private Context context;
    private List<GoodsBean.DataBean.LineBean> list;

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.shop_search_goods_item, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(list.get(i).getThumbPath()).into(holder.shopSearchIv);
        holder.shopSearchTitle.setText(list.get(i).getTitle());
        holder.shopSearch.setText(list.get(i).getPrice());
        return view;
    }
    static class ViewHolder {
        @Bind(R.id.shop_search_iv)
        ImageView shopSearchIv;
        @Bind(R.id.shop_search_title)
        TextView shopSearchTitle;
        @Bind(R.id.shop_search_)
        TextView shopSearch;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
